//
//  CartoonListCollectionViewCell.swift
//  UUCartoon
//
//  Created by Galaxy on 2021/6/8.
//  Copyright © 2021 qykj. All rights reserved.
//

import UIKit
import Kingfisher
class CartoonListCollectionViewCell: UICollectionViewCell {

    @IBOutlet weak var backViewConstraintWidth: NSLayoutConstraint!
    @IBOutlet weak var topImg: UIImageView!
    @IBOutlet weak var titleLab: UILabel!
    @IBOutlet weak var authorLab: UILabel!
    @IBOutlet weak var authConstrainHeight: NSLayoutConstraint!
    @IBOutlet weak var imageHeight: NSLayoutConstraint!
    
    public var cartoonModel:CartoonModel = CartoonModel.init() {
        didSet{
            if Tool().isPhone() {
                backViewConstraintWidth.constant = screenW/3
            }else{
                backViewConstraintWidth.constant = 125
            }
            let modifier = AnyModifier { request in
                var r = request
                r.setValue(urlArr[self.cartoonModel.type.rawValue], forHTTPHeaderField: "Referer")
                return r
            }
            topImg.kf.setImage(with: URL.init(string: cartoonModel.imgUrl), placeholder: UIImage.init(named: "placeholder"), options: [.requestModifier(modifier)]) { result in
//                switch result{
//                case .success(let image):
//                    let imageWidth = image.image.size.width
//                    let imageHeight = image.image.size.height
//                    if Tool().isPhone(){
//                        self.imageHeight.constant = imageHeight*(screenW/3-10)/imageWidth
//                    }else{
//                        self.imageHeight.constant = imageHeight*115/imageWidth
//                    }
//                case .failure(let error):
//                    print(error.localizedDescription)
//                }
            }
            titleLab.text = cartoonModel.name
            if cartoonModel.author.isEmpty {
                authConstrainHeight.constant = 0
            }
            authorLab.text = cartoonModel.author
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
}
